package com.bit.spring_mybatisdemo1.mapper;

import com.bit.spring_mybatisdemo1.model.UserInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserInfoMapper {

    @Select("select * from user_info")
    public List<UserInfo> selectAllUser();

    @Select("select * from user_info where id=3")
    public List<UserInfo> selectId1();

    @Select("select * from user_info where id=#{id}")
    public List<UserInfo> selectId2(Integer id);

    @Select("select * from user_info where username=#{username}")
    public List<UserInfo> selectUsername1(@Param("username") String name);

    @Select("select * from user_info where username=#{username}")
    public List<UserInfo> selectUsername2(UserInfo info);

    //通过起别名的方式进行映射
    @Select("select id,username,delete_flag as deleteFlag,create_time as createTime from user_info where id=#{id}")
    public List<UserInfo> selectId3(Integer id);

    //通过注解进行映射
    @Results(value = {
            @Result(column = "delete_flag",property = "deleteFlag"),
            @Result(column = "create_time",property = "createTime"),
            @Result(column = "update_time",property = "updateTime")
    },id="resultMap")
    @Select("select * from user_info")
    public List<UserInfo> selectAllUser2();

    //通过给@Results注解的id属性赋值进行命名并实现复用
    @ResultMap("resultMap")
    @Select("select * from user_info")
    public List<UserInfo> selectAllUser3();

    @Select("select * from user_info")
    public List<UserInfo> selectAllUser4();


}
